package cn.tedu.sp03.service;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp01.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private UserClient userClient;
    @Autowired
    private ItemClient itemClient;
    @Override
    public Order getOrder(String oredrId) {
        log.info("获取订单,orderId="+oredrId);
        //TODO: 远程调用商品,获取商品列表
        //TODD: 远程调用用户,获取用户数据
        JsonResult<List<Item>> item = itemClient.getItems(oredrId);
        JsonResult<User> user = userClient.getUser(8);
        Order order = new Order();
        order.setId(oredrId);
        order.setItems(item.getData());
        order.setUser(user.getData());
        return order;
    }
    //远程调用用户,获取用户数据
    //使用已登录的id

    @Override
    public void create(Order order) {
        log.info("订单");
        itemClient.decreaseNumber(order.getItems());

        userClient.addScore(order.getUser().getId(), 1000);
    }
}
